<!--三包法规查询 厂端-->
<template>
  <div>
    <TopFilter ref="topfilter" :list="topFilterList" :cols="4" labelWidth="100" :collapse="true" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      :isExportExcel="false"
      exportFileName="三包法规查询.xlsx"
      :onCalcExportData="handleExportFun"
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      datakey="records"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    >
<!--      <template slot="controls" slot-scope="props">-->
<!--        <multiuse-button type="primary" :click="exportHandle.bind(this)">导出</multiuse-button>-->
<!--      </template>-->
    </FilterTable>

    <Drawer :visible.sync="visibleDetail" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <detail :threeId="threeId" @save="editSave" @close="closeHandler" :handleType="handleType" />
    </Drawer>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import detail from './detail';
import { dealerMixin } from '@/pages/repair/batchEventManagement/dealerMixin';
import { isEmpty } from '@/utils/utils';
import {listRecord, exportListRecord, listRecordNew} from '@/api/repair/threePacksOfManager/regulationsQueryCDuan';
import { arrayObjDeWeight } from '@/utils';

export default {
  name: 'addItem',
  mixins: [dictionary, dealerMixin],
  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑', show: '三包预警规则编辑' };
    return {
      topFilterList: this.createTopFilterList(),
      visible: false,
      visibleDetail: false,
      fetchApi: listRecordNew,
      dialogTitle: '',
      fetchParams: { xhrAbort: false },
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      threeId: ''
    };
  },
  components: {
    detail
  },

  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    editSave() {
      this.visibleDetail = false;
      this.fetchParams = { ...this.fetchParams };
    },
    async exportHandle() {
      const [err, params] = await this.$refs.topfilter.GET_FORM_DATA();

      await this.downHandleFile(exportListRecord, params, '三包法规查询');
    },

    // 导出处理函数
    handleExportFun(row) {
      row.type = this.createDictText(row.type, 1023);
    },

    detailHandle(row) {
      this.threeId = row['threeId'];
      this.handleType = 'show';
      this.showHandler();
    },

    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '规则编号',
          dataIndex: 'threeNo',
          sorter: true,
          width: 100,
        },
        {
          title: '规则名称',
          dataIndex: 'name',
          sorter: true,
          width: 170,
        },
        // {
        //   title: '规则类型',
        //   dataIndex: 'type',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList(1023),
        //   render: props => {
        //     return <span>{this.createDictText(props.row.type, 1023)}</span>;
        //   }
        // },

        {
          title: '规则描述',
          dataIndex: 'remarks',
          sorter: true,
          showOverflowTooltip: false,
        },
        {
          title: '法定时限（月）',
          dataIndex: 'months',
          sorter: true,
          width: 150,
        },
        {
          title: '法定里程（公里）',
          dataIndex: 'mileage',
          sorter: true,
          width: 150,
        },
        {
          title: '状态',
          dataIndex: 'isDeletedStr',
          sorter: true,
          width: 100,
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 70,
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>
                  修改
                </el-button>
              </div>
            );
          }
        },
      ];
    },
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '规则编号',
          fieldName: 'threeNo',
          placeholder: '规则编号...'
        },
        {
          type: 'INPUT',
          label: '规则名称',
          fieldName: 'name',
          placeholder: '规则名称...'
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'isDeleted',
          initialValue: '',
          itemList: [
            { text: '有效', value: '0' },
            { text: '无效', value: '1' }
          ]
        }
        // {
        //   type: 'SELECT',
        //   label: '规则类型',
        //   fieldName: 'type',
        //   placeholder: '规则类型',
        //   itemList: this.createDictList(1023)
        // }
      ];
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    changeHandle(val) {
      // val.bDate=moment(val['bDate']).format('YYYY-MM-DD')
      // val.eDate=moment(val['eDate']).format('YYYY-MM-DD')
      this.fetchParams = Object.assign({}, val);

      console.log(this.fetchParams);
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}`;

      this.visibleDetail = true;
    },

    closeHandler(type) {
      this.visible = false;
      this.visibleDetail = false;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
